myApp.controller('addSize', ['$scope', '$http', '$size', function($scope, $http, $size){
	$scope.sizeName = "";
	$scope.sizeDescription = "无";
	$scope.addSize = function() {
		if($scope.sizeName === "") {
			alert("请填写需要添加的尺寸名称！");
		}else {
			var sizeData = {"size.name": $scope.sizeName, "size.description": $scope.sizeDescription};

			var postCfg = {
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				transformRequest: function (data) {
					return $.param(data);
				}
			};

			$http.post('addSize', sizeData, postCfg).then(function successCallback(response) {
				alert("已添加成功！");
				$scope.sizeName = "";
				$scope.sizeDescription = "无";

				var promise = $size.loadAllSize();
				promise.then(function(data) {
					$size.allSize = data;
				}, function(n) {
					$size.allSize = [{"name": "数据加载出错！"}];
				});
				console.log("ok：" + response);
			}, function errorCallback(response) {
				console.log("fail：" + response);
			});
		}
	};
}]);

myApp.controller('deleteSize', ['$scope', '$http', '$size', function($scope, $http, $size){
	
	$scope.sizeId = "";
	$scope.deleteSize = function() {
		if ($scope.sizeId === "" || $scope.sizeId === null) {
			alert("请选择需要删除的尺寸！");
		}else {
			var sizeData = {"size.sizeId": $scope.sizeId};

			var postCfg = {
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				transformRequest: function (data) {
					return $.param(data);
				}
			};

			$http.post('deleteSize', sizeData, postCfg).then(function successCallback(response) {
				alert("已删除成功！");
				$scope.sizeId = "";

				var promise = $size.loadAllSize();
				promise.then(function(data) {
					$size.allSize = data;
				}, function(n) {
					$size.allSize = [{"name": "数据加载出错！"}];
				});
				console.log("ok：" + response);
			}, function errorCallback(response) {
				console.log("fail：" + response);
			});
		}
		
	};
}]);

myApp.controller('modifySize', ['$scope', '$http', '$size', function($scope, $http, $size){
	
	$scope.sizeId = "";
	$scope.sizeName = "";
	$scope.sizeDescription = "无";
	$scope.modifySize = function() {
		if($scope.sizeId === "" || $scope.sizeId === null) {
			alert("请选择需要修改的尺寸！");
		}else if ($scope.sizeName === "") {
			alert("请填写尺寸名称！");
		}else {
			var sizeData = {"size.sizeId": $scope.sizeId, "size.name": $scope.sizeName, "size.description": $scope.sizeDescription};
			var postCfg = {
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				transformRequest: function (data) {
					return $.param(data);
				}
			};

			$http.post('modifySize', sizeData, postCfg).then(function successCallback(response) {
				alert("已修改成功！");
				$scope.sizeId = "";
				$scope.sizeName = "";
				$scope.sizeDescription = "无";

				var promise = $size.loadAllSize();
				promise.then(function(data) {
					$size.allSize = data;
				}, function(n) {
					$size.allSize = [{"name": "数据加载出错！"}];
				});
				console.log("ok：" + response);
			}, function errorCallback(response) {
				console.log("fail：" + response);
			});
		}
		
	};
}]);